home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 1 of 3 / CHAPTE21 / EX6.C < prev    next >
C/C++ Source or Header  |  1995-05-29  |  2KB  |  49 lines

  1. #include <genstub.c>
  2.  
  3. LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  4. {
  5.    static char szSaveEnvVar[128];
  6.    switch (uMsg)
  7.    {
  8.          case WM_CREATE:
  9.                GetEnvironmentVariable( "Test", szSaveEnvVar, MAX_PATH + 1 );
  10.                return DefWindowProc( hWnd, uMsg, wParam, lParam );
  11.          case WM_COMMAND:
  12.                switch ( LOWORD( wParam ) )
  13.                {
  14.                      case IDM_TEST:   // Sets Env Var "Test" to token on command line.
  15.                      {
  16.                            char   szMessage[2*( MAX_PATH + 1 )];
  17.                            char   szCommandLine[256];
  18.                            LPTSTR lpTemp = NULL;
  19.  
  20.                            // Read command line into local buffer.
  21.                            lstrcpy( szCommandLine, GetCommandLine() );
  22.  
  23.                            // Search for extra input after program name.
  24.                            lpTemp = strstr( szCommandLine, " " );
  25.                            if (lpTemp)
  26.                               lpTemp = strtok(lpTemp, " ");
  27.  
  28.                            // "Test" is removed from environment if there is no token.
  29.                            SetEnvironmentVariable( "Test", lpTemp );
  30.                            // Show change in message box.
  31.                            wsprintf( szMessage, "'Test' was [%s], New Value=[%s]",
  32.                                      szSaveEnvVar, lpTemp );
  33.                            MessageBox( hWnd, szMessage,
  34.                                        "Changing Environment Variable", MB_OK );
  35.                      }
  36.                      break;
  37.                      case IDM_EXIT:
  38.                            DestroyWindow( hWnd );
  39.                            break;
  40.                }
  41.                break;
  42.          case WM_DESTROY:
  43.                PostQuitMessage( 0 );
  44.                break;
  45.          default:
  46.                return (DefWindowProc(hWnd, uMsg, wParam, lParam));
  47.    }
  48.    return (NULL);
  49. }